version 14.1
set more off
set matsize 11000

***************************************************************************************************
* THIS ROUTINE GENERATES TABLE A.VIII OF WASEEM (2019) RESTAT
***************************************************************************************************

/* TABLE */

#d				;
matrix 			input table=(0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0\
							 0,0,0,0,0,0,0,0,0\0,0,0,0,0,0,0,0,0);
#d				cr

/* DEFINING TIME VARIABLE */		

use				"$project_data\ExemptionCutoff_06_11.dta",clear
keep			if employee==0
replace			taxableinc=seinc if taxableinc==0 | taxableinc==.
sort			regnor year
local 			var="taxableinc"
local			lbound=80000
local			ubound=500000

/* LOG CHANGE IN EARNINGS */

keep 			`var' regnor year industry2 taxableinc seinc location_code
g 				double z0=`var'
g 				z1=F1.`var'
g 				logchange=log(z1/z0)
g 				double z0s=seinc
g 				z1s=F1.seinc
keep 			if z0s>80000 & z0s<=500000
g 				logchanges=log(z1s/z0s)
qui				sum logchanges,d
drop			if (logchanges<r(p1) | logchanges>r(p99)) & year<2011
g				logz0=log(z0)
mkspline 		z0s 10 = logz0

/* GENERATING TREATMENT DUMMIES */

g				tozero=(`var'<=350000)
g				nottozero=(`var'>400000)
g				m_09=(`var'<=300000 & year==2009)
g				m_10=(`var'<=350000 & year==2010)
g				t_09=(`var'>400000 & year==2009)
g				trend=1
local			i=1
forvalues		y=2007/2011 {
local			i=`i'+1
replace			trend=`i' if year==`y'
}
g				post=year>2008
drop			if year==2011

/* COLUMN (1) */

local			i=1
local			j=1
qui				reg logchange i.year logz0 z0s* tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)

/* COLUMN (2) -- LINEAR */

local			i=1
local			j=`j'+1
qui				reg logchange trend logz0 z0s* tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 
matrix			table[`i',`j']=r(mean)

/* COLUMN (3) -- INDUSTRY-SPECIFIC */

local			i=1
local			j=`j'+1
qui				reg logchange i.year logz0 z0s* i.industry2 tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (4) -- INDUSTRY-FE */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.industry2 logz0 z0s* tozero nottozero m_09 m_10 t_09, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (5) -- REGION-FE */

local			i=1
local			j=`j'+1
qui				reg logchange i.year logz0 z0s* i.location_code tozero nottozero m_09 m_10 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (6) -- REGUION-SPECIFIC */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.location_code logz0 z0s* tozero nottozero m_09 m_10 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* COLUMN (7) -- REGUION-SPECIFIC & INDUSTRY-SPECIFIC */

local			i=1
local			j=`j'+1
qui				xi: reg logchange i.year*i.location_code i.year*i.industry2 logz0 z0s* tozero nottozero m_09 m_10 t_09 if location_code>0, cluster(regnor) 
matrix			table[`i',`j']=_b[m_09]
matrix			table[`i'+1,`j']=_se[m_09]
local			i=`i'+2
matrix			table[`i',`j']=_b[m_10]
matrix			table[`i'+1,`j']=_se[m_10]
local			i=`i'+2
matrix			table[`i',`j']=_b[t_09]
matrix			table[`i'+1,`j']=_se[t_09]
local			i=`i'+2
matrix			table[`i',`j']=e(N)
local			i=`i'+1
qui				sum logchange if post==0 & industry2!=.
matrix			table[`i',`j']=r(mean)

/* FORMATTING TABLE */ 

svmat 			table
keep			tab*
drop			table8-table9
keep			if _n<=8
g				c11=""
replace			c11="$\mbox{\emph{to-zero}} \times 2009$" in 1
replace			c11="$\mbox{\emph{to-zero}} \times 2010$" in 3
replace			c11="$\mbox{\emph{not-to-zero}} \times 2009$" in 5
replace			c11="Observations" in 7
forvalues 		c=1/7 {
g				c`c'=string(table`c',"%9.3f")
}
forvalues		r=2(2)6 {
forvalues		c=1/7 {
replace			c`c'="("+string(table`c',"%9.3f")+")" in `r'
}
}
forvalues		c=1/7 {
replace			c`c'=string(table`c',"%15.0fc") in 7
}
forvalues		s=1/8 {
g				s`s'="&"
}
g				l="\\"
replace			l="\\\\" in 6
browse			c11 s8 c1 s1 c2 s2 c3 s3 c4 s4 c5 s5 c6 s6 c7 l
